import request from '@/utils/request'
import { ISaveRoleData, IRoleResponseMenu, IResponseEditRole } from './types/role'

// 获取角色列表
export const getRoleList = () => {
  return request({
    method: 'POST',
    url: '/user/roles/list'
  })
}

// 增加修改角色
export const upSaveRole = (params: {
  id: number | null
}) => {
  return request({
    method: 'POST',
    url: '/user/roles/save',
    params
  })
}

// 删除角色
export const deleteRole = (params: {
  id: number
}) => {
  return request({
    method: 'POST',
    url: '/user/roles/del'
  })
}

// 查看详情
export const getRoleInfo = (params: {
  id: number
}) => {
  return request({
    method: 'get',
    url: '/user/roles/info'
  })
}

// 保存角色
export const saveRole = (id: number, data: ISaveRoleData) => {
  return request({
    method: 'POST',
    url: `setting/role/${id}`,
    data
  })
}

// 修改角色状态
export const updateRoleStatus = (id:number, status: 0 | 1) => {
  return request({
    method: 'PUT',
    url: `/setting/role/set_status/${id}/${status}`
  })
}

// 获取权限列表
export const getRoleMenus = () => {
  return request<{
    menus: IRoleResponseMenu[]
  }>({
    method: 'GET',
    url: '/setting/role/create'
  })
}

// 编辑权限管理详情
// status 0 新增 1编辑
export const getRole = (id: number) => {
  return request<{
    role: IResponseEditRole,
    menus: IRoleResponseMenu[]
  }>({
    method: 'GET',
    url: `/setting/role/${id}/edit`
  })
}
